1 using UnityEngine;
2 using
System.Collections;
3
4 public
class Info : MonoBehaviour {
5
6     
private Rect rect;
7     
private Texture2D texture;
8
9     
private float dis;
10
11     
private bool isVisible;
12
13     
void Start () {
14         texture = gameObject.GetComponent<SpriteRenderer>().sprite.texture;
15         rect =
new Rect(0, 642, 300, 325);
16         updateRect();
17     }
18     
19     
void Update () {
20         resetSprite();
21
22         
if (!isVisible)
23         {
24             isVisible =
true;
25             gameObject.SetActive(
true);
26         }
27     }
28
29     
private void resetSprite()
30     {
31         gameObject.GetComponent<SpriteRenderer>().sprite = Sprite.Create(texture, rect, Vector2.zero);
32         dis =
100 * Time.deltaTime;
33         rect.y -= dis;
34
35         updateRect();
36     }
37
38     
private void updateRect()
39     {
40         
if (rect.y <= -325)
41             rect.y =
642;
42         
if (rect.y > 316)
43             rect.height =
642 - rect.y;
44         
else
45             rect.height =
325;
46     }
47
48 }



Trò chơi đua xe động vật trong UNITY Engine 114.780 lượt xem

Gõ tìm kiếm nhanh...